package com.mdlib.helper.ui.adapter;

import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ljlib.core.util.common.TimeUtils;
import com.ljlib.help.R;
import com.mdlib.helper.model.entity.VoucherEntity;

import java.util.List;

/**
 * 作者：HQY on 16/11/17 13:12
 * 邮箱：hqy_xz@126.com
 */

public class VoucherAdapter extends BaseQuickAdapter<VoucherEntity> {


    public VoucherAdapter(List<VoucherEntity> data) {
        super(R.layout.item_voucher_condition, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, VoucherEntity voucherEntity) {

        ImageView itembg = baseViewHolder.getView(R.id.iv_voucher_bg);

        TextView tvCoupon = baseViewHolder.getView(R.id.tv_voucher_coupon);
        baseViewHolder.setText(R.id.tv_voucher_money, voucherEntity.getValue());

        baseViewHolder.setText(R.id.tv_voucher_title, voucherEntity.getTitle())
                .setText(R.id.tv_voucher_time, TimeUtils.milliseconds2String(Long.valueOf(voucherEntity.getExpireTime()) * 1000, TimeUtils.SUCCESS_MONTH));
        if (voucherEntity.getStatus() == -2) {
            itembg.setImageResource(R.drawable.iv_voucher_unused_bg);
            tvCoupon.setTextColor(mContext.getResources().getColor(R.color.voucher_tv_un_color));
            baseViewHolder.setText(R.id.tv_voucher_type, mContext.getResources().getString(R.string.voucher_tv_title_hasbeenused));
        } else if (voucherEntity.getStatus() == -1) {
            itembg.setImageResource(R.drawable.iv_voucher_unused_bg);
            tvCoupon.setTextColor(mContext.getResources().getColor(R.color.voucher_tv_un_color));
            baseViewHolder.setText(R.id.tv_voucher_type, mContext.getResources().getString(R.string.voucher_tv_title_expired));
        } else {
            itembg.setImageResource(R.drawable.iv_voucher_used_bg);
            tvCoupon.setTextColor(mContext.getResources().getColor(R.color.voucher_tv_color));
            baseViewHolder.setText(R.id.tv_voucher_type, mContext.getResources().getString(R.string.voucher_tv_title_unused));
        }

    }
}
